﻿using K8.CBB;
using KingerRobot.PCRBW.Dao;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace KingerRobot.PCRBW.SpiService;

public class MesProductImpl: IMesProductService
{
    IMesProductRepositories _productRepositories = new MesProductRepositories();
    public MesProduct QueryById(string objId)
    {
        return _productRepositories.QueryById(objId);
    }

    public MesProduct QueryByEquipName(string equipName)
    {
        Expression<Func<MesProduct, bool>> whereMesProductExpression = x => true;
        whereMesProductExpression = whereMesProductExpression.And(d => d.EquipName == equipName);
        return _productRepositories.First(whereMesProductExpression);
    }

    public int UpdateByStatus(MesProduct mesProduct)
    {
        Expression<Func<MesProduct, bool>> whereMesProductExpression = x => true;
        whereMesProductExpression = whereMesProductExpression.And(d => d.Id == mesProduct.Id);
        return _productRepositories.Update(whereMesProductExpression,mesProduct);
    }
    public int SyncMesProduct(MesProduct mesProduct)
    {
        Expression<Func<MesProduct, bool>> whereMesProductExpression = x => true;
        whereMesProductExpression = whereMesProductExpression.And(d => d.Id == mesProduct.Id);
        var mespro = _productRepositories.First(whereMesProductExpression);
        if (mespro != null)
        {
            return _productRepositories.Update(whereMesProductExpression,mesProduct);
        }
        else
        {
            return _productRepositories.Add(mesProduct);
        }
    }

    public int DeleteByTask(MesProduct mesProduct,POWcsTask wcsTask,POWcsTaskCmd wcsTaskCmd)
    {
        return _productRepositories.ExecDeleteByTaskTran(mesProduct, wcsTask, wcsTaskCmd);
       
    }
}
